<!--  -->
<template>
  <div class="device-detail animate__animated animate__zoomIn">
    <div v-if="!loadingFlag" class="device-detail-top">
      <dv-decoration-11 style="width: 30%; height: 50%; font-size: 0.3rem"
        >设备 综合信息</dv-decoration-11
      >
      <div class="goback">
        <GoBack></GoBack>
      </div>
      <div class="goindex">
        <GoIndex></GoIndex>
      </div>
    </div>
    <div v-if="!loadingFlag" class="device-detail-tab">
      <!-- 基本信息 -->
      <div class="detail-box detail5 detail-full">
        <div class="box-info">
          <dv-border-box-2>
            <div class="info-top">
              <div class="top-title">
                <span>基本信息</span>
              </div>
              <!-- <div class="top-tip">
                <span>超期未检</span>
                <span>预警</span>
                <span>事故</span>
                <span>举报</span>
              </div> -->
            </div>
            <div class="info-main">
              <ul>
                <li>
                  <div class="li-box">
                    <span>使用单位</span>
                    <span class="link-blue"
                       @click="toUnitDetail(infoData.use_com_id)">{{ infoData.use_com_name }}</span>
                  </div>
                  <div class="li-box">
                    <span>制造单位：</span>
                    <span>{{ infoData.make_com_name }}</span>
                  </div>
                </li>
                <li>
                  <div class="li-box">
                    <span>施工单位</span>
                    <span>{{ infoData.ins_com_name }}</span>
                  </div>
                  <div class="li-box">
                    <span>设计单位</span>
                    <span>{{ infoData.des_com_name }}</span>
                  </div>
                </li>
                <li>
                  <div class="li-box">
                    <span>维保单位</span>
                    <span>{{infoData.maint_com_name}}</span
                    >
                  </div>
                  <div class="li-box">
                    <span>设备类型</span>
                    <span>{{ infoData.kind_code_name }}</span>
                  </div>
                </li>
                <li>
                  <div class="li-box">
                    <span>设备代码</span>
                    <span>{{ infoData.dev_no }}</span>
                  </div>
                  <div class="li-box">
                    <span>设备名称</span>
                    <span>{{ infoData.dev_name }}</span>
                  </div>
                </li>
                <li>
                  <div class="li-box">
                    <span>安全管理员</span>
                    <span>{{ infoData.staff_name }}</span>
                  </div>
                  <div class="li-box">
                    <span>设备地址</span>
                    <span>{{ infoData.dev_address }}</span>
                  </div>
                </li>
              </ul>
            </div>
          </dv-border-box-2>
        </div>
      </div>
      <!-- 检验信息 -->
      <div class="detail-box detail5">
        <div class="box-info">
          <dv-border-box-2>
            <div class="info-top">
              <div class="top-title">
                <span>检验信息</span>
              </div>
              <!-- <div class="top-tip">
                <span>事故总数：25 起</span>
                <span>应急救援总数：2 起</span>
              </div> -->
            </div>
            <div class="info-main">
              <ul>
                <PublicListSmall :revListData="listData2"></PublicListSmall>
              </ul>
            </div>
          </dv-border-box-2>
        </div>
      </div>
      <!-- 技术档案信息 -->
      <div class="detail-box detail5">
        <div class="box-info">
          <dv-border-box-2>
            <div class="info-top">
              <div class="top-title">
                <span>技术档案信息</span>
              </div>
            </div>
            <div class="info-main">
              <ul>
                <PublicListSmall :revListData="listData4"></PublicListSmall>
              </ul>
            </div>
          </dv-border-box-2>
        </div>
      </div>
    </div>
    <div v-if="loadingFlag" class="e-loading">
      <dv-loading style="color: #fff; opcity: 0.5"
        >设备列表数据加载中...</dv-loading
      >
    </div>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import PublicListSmall from "../list/PublicListSmall";

export default {
  //import引入的组件需要注入到对象中才能使用
  components: { PublicListSmall },
  data() {
    //这里存放数据
    return {
      infoData: {},
      listData2: {
        head: [
          { name: "报告编号", prop: "p1" },
          { name: "下次检验日期", prop: "p2" },
          { name: "检验结论", prop: "p3" },
          { name: "主要问题", prop: "p4" },
          { name: "检验单位", prop: "p5" },
        ],
        body: [],
      },
      listData4: {
        head: [
          { name: "技术档案信息", prop: "p1" },
          { name: "档案类型", prop: "p2" },
          { name: "上传时间", prop: "p3" },
          { name: "操作", prop: "col" },
        ],
        body: [
          // {
          //   p1: "姚独立一行",
          //   p2: "2020-11-11",
          //   p2: "2020-11-11",
          //   col: "",
          // },
        ],
      },
      loadingFlag: true
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    toUnitDetail(id) {
      console.log('维保ID：' + id);
      this.$router.push({
        name: 'companyList-detail',
        params: {id}
      });
    },

    async init() {
      this.loadingFlag = true
      let id = this.$route.params.id;
      console.log("接收的设备ID: " + id);
      await this.getDevDetail(id);
    },

    async getDevDetail(id) {
      let ret = await this.$http.postGetDevInfoById({ id: parseInt(id) });
      ret = ret.data;
      if (ret.errorCode != 0) {
        return console.log("数据有误！");
      }
      console.log(ret.data);
      // 检验信息
      this.listData2.body = [
        {
          p1: ret.data.devCheckInfo ? ret.data.devCheckInfo.reportNo : '',
          p2: ret.data.devCheckInfo ? ret.data.devCheckInfo.verifyDateNext : '',
          p3: ret.data.devCheckInfo ? ret.data.devCheckInfo.verifyResult : '',
          p4: ret.data.devCheckInfo ? ret.data.devCheckInfo.mainProblem : '',
          p5: ret.data.devCheckInfo ? ret.data.devCheckInfo.verifyCom : '',
        },
      ];

      // 基本信息
      Object.assign(this.infoData, ret.data.devComsInfo, ret.data.devInfo)
      console.log(this.infoData);

      // 技术档案信息
      this.listData4.body = []
      if (ret.data.devFiles) {
        var fileNum = 0
        ret.data.devFiles.forEach(ele => {
          if (fileNum >= 4) return
          // console.log(ele);
          let map = {
            p1: ele.title,
            p2: ele.dict_label,
            p3: ele.create_time,
            col: ele.title,
          }
          this.listData4.body.push(map)
          fileNum++
        });
      }

      this.loadingFlag = false
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.init();
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  beforeRouteEnter(to,form,next) {
    if (JSON.stringify(to.params)=="{}") {
      to.meta.isBack = true
    }else{
      to.meta.isBack = false
    }
    next()
  },
  activated() {
    if (!this.$route.meta.isBack) {
      console.log('需要刷新');
      this.init()
    }else{
      console.log('缓存页面');
    }
  },
};
</script>
<style lang='less' scoped>
//@import url(); 引入公共css类
.device-detail {
  width: 100%;
  height: 100%;
  .device-detail-top {
    width: 100%;
    height: 15%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    color: @FontColor;
    .goback {
      position: absolute;
      left: 0;
      top: 2%;
    }
  }
  .device-detail-tab {
    width: 100%;
    height: 85%;
    display: flex;
    flex-wrap: wrap;
    .detail-box {
      width: 50%;
      height: 45%;
      display: flex;
      justify-content: center;
      align-items: center;
      .box-info {
        width: 95%;
        height: 100%;
        .info-top {
          width: 100%;
          height: 20%;
          // background-color: pink;
          display: flex;
          .top-title {
            width: 30%;
            height: 100%;
            display: flex;
            justify-content: flex-start;
            align-items: center;
            // background-color: #ccc;
            padding-left: 0.3rem;
            span {
              font-size: 0.24rem;
              font-weight: 700;
              color: @Green;
            }
          }
          .top-tip {
            width: 70%;
            height: 100%;
            display: flex;
            justify-content: space-evenly;
            align-items: center;
            span {
              font-size: 0.18rem;
              color: @FontColor;
              // color: #ffe680;
              font-weight: 700;
            }
          }
        }
        .info-main {
          width: 100%;
          height: 78%;
          ul {
            width: 90%;
            height: 90%;
            margin: 0 auto;
            li {
              width: 100%;
              height: 20%;
              display: flex;
              .li-box {
                flex: 1;
                color: #eee;
                font-size: 0.18rem;
                display: flex;
                justify-content: space-evenly;
                align-items: center;
                span {
                  display: block;
                  text-align: left;
                  width: 100%;
                  height: 80%;
                }
                span:first-child {
                  color: #ccc;
                  font-weight: 700;
                }
              }
            }
          }
        }
      }
    }
    .detail-full.detail-box {
      width: 100%;
      .box-info {
        width: 97.5%;
      }
    }
  }
}
</style>